package com.example.puzzle;

import android.app.Activity;
import android.os.Bundle;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.widget.TextView;

public class MainActivity extends Activity {

    private GamePintuLayout mGamePintuLayout;
    private TextView mLevel;
    private TextView mTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTime = (TextView) findViewById(R.id.id_time);
        mLevel = (TextView) findViewById(R.id.id_level);
        mGamePintuLayout = (GamePintuLayout) findViewById(R.id.id_gamepintu);
        mGamePintuLayout.setTimeEnabled(true);
        mGamePintuLayout.setOnGamePintuListener(new GamePintuLayout.GamePintuListener() {
            @Override
            public void timechanged(int currentTime) {
                mTime.setText("" + currentTime);
            }
            @Override
            public void nextLevel(final int nextLevel) {
                new AlertDialog.Builder(MainActivity.this)
                        .setTitle("GAME INFO").setMessage("LEVEL UP!!!")
                        .setPositiveButton("NEXT LEVEL", new OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                mGamePintuLayout.nextLevel();
                                mLevel.setText("" + nextLevel);
                            }

                        }).show();
            }

            @Override
            public void gameover() {
                new AlertDialog.Builder(MainActivity.this)
                        .setTitle("GAME INFO").setMessage("GAME OVER!!!")
                        .setPositiveButton("RESTART", new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                // mGamePintuLayout.nextLevel();
                                mGamePintuLayout.restart();
                            }

                        }).setNegativeButton("QUIT", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog,
                                        int which) {
                        finish();
                    }
                }).show();
            }
        });
    }
    @Override
    protected void onPause() {
        super.onPause();
        mGamePintuLayout.pause();
    }
    @Override
    protected void onResume() {
        super.onResume();
        mGamePintuLayout.resume();
    }
}